Skip to content

Conversation

aniaan
Copy link
Contributor

@aniaan aniaan commented Oct 1, 2020

Add the check of ascending parameter in the sortlevel method, only allow bool value and single bool value list

cc @Dr-Irv

Copy link
Contributor

@Dr-Irv Dr-Irv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. Can you add a whatsnew entry for v1.2 ?

@Dr-Irv Dr-Irv added this to the 1.2 milestone Oct 1, 2020
@aniaan
Copy link
Contributor Author

aniaan commented Oct 1, 2020

Looks good. Can you add a whatsnew entry for v1.2 ?

I have added the v1.2 whatsnew entry , please take a look

@@ -352,7 +352,7 @@ Indexing
- Bug in :meth:`PeriodIndex.get_loc` incorrectly raising ``ValueError`` on non-datelike strings instead of ``KeyError``, causing similar errors in :meth:`Series.__geitem__`, :meth:`Series.__contains__`, and :meth:`Series.loc.__getitem__` (:issue:`34240`)
- Bug in :meth:`Index.sort_values` where, when empty values were passed, the method would break by trying to compare missing values instead of pushing them to the end of the sort order. (:issue:`35584`)
- Bug in :meth:`Index.get_indexer` and :meth:`Index.get_indexer_non_unique` where int64 arrays are returned instead of intp. (:issue:`36359`)
-
- Bug in :meth:`Index.sortlevel` where, add the check of ascending parameter in the sortlevel method, only allow bool value and single bool value list. (:issue:`32334`)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better to say

Bug in :meth:`DataFrame.sort_index` where parameter ascending passed as a list on a single level index gives wrong result. (:issue:`32334`)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

whatsnew has been adjusted, please take a look

@Dr-Irv Dr-Irv merged commit a3da05a into pandas-dev:master Oct 1, 2020
@Dr-Irv
Copy link
Contributor

Dr-Irv commented Oct 1, 2020

thanks @BEANNAN

@jreback jreback added the Typing type annotations, mypy/pyright type checking label Oct 1, 2020
Copy link
Contributor

@jreback jreback left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Dr-Irv ideally this would have had more review

@@ -2222,6 +2222,31 @@ def test_contains_method_removed(self, index):
with pytest.raises(AttributeError, match=msg):
index.contains(1)

def test_sortlevel(self):
index = pd.Index([5, 4, 3, 2, 1])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we generally add the issue number here as a comment

with pytest.raises(Exception, match="ascending must be a bool value"):
index.sortlevel(ascending=["True"])

expected = pd.Index([1, 2, 3, 4, 5])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should be 2 tests, one for the exceptions, one for the working cases (which could be parameterized)

@@ -1515,6 +1515,20 @@ def sortlevel(self, level=None, ascending=True, sort_remaining=None):
-------
Index
"""
if not isinstance(ascending, (list, bool)):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these should be checked at a much lower level, where they are used; the reason these are fairly generic things not specific to Index in this case

@aniaan aniaan deleted the bugfix/GH32334 branch October 5, 2020 05:57
kesmit13 pushed a commit to kesmit13/pandas that referenced this pull request Nov 2, 2020
…ndas-dev#36767)

* BUG: Index sortlevel ascending add type checking pandas-dev#32334

* DOC: add v1.2 whatsnew entry pandas-dev#32334

* BUG: adjust judgment conditions, len(ascending) > 1 => len(ascending) != 1

* DOC: adjustment whatsnew

Co-authored-by: beanan <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Typing type annotations, mypy/pyright type checking
Projects
None yet
Development

Successfully merging this pull request may close these issues.

DataFrame.sort_index() with ascending passed as a list on a single level index gives wrong result
3 participants